﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Classes;

namespace OfficeManager_v0._1
{
    public partial class AssignProject : Form
    {
        Department mDepartment;
        Organization mOrganization;
        public AssignProject(Organization aOrganization, Department aDepartment)
        {
            mOrganization = aOrganization;
            mDepartment = aDepartment;
            InitializeComponent();

            comboBoxProject.DropDownStyle = ComboBoxStyle.DropDownList;
            PopulateComboBox();
        }

        private void PopulateComboBox()
        {
            comboBoxProject.Enabled = false;
            foreach (Project project in mOrganization.Projects)
            {
                if (project.Department != null)
                    continue;

                comboBoxProject.Enabled = true;
                comboBoxProject.Items.Add(project.Subject);
            }
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                Project target = mOrganization.Projects.Find((proj) =>
                    {
                        return string.Compare(proj.Subject,
                            comboBoxProject.GetItemText(comboBoxProject.SelectedItem)) == 0;
                    });

                target.Department = mDepartment;
                mDepartment.Projects.Add(target);
            }
            catch (Exception exc)
            {
                MessageBox.Show("Въведените данни за некоректни!");
            }

            this.Close();
            this.Dispose();
        }
    }
}
